﻿using System;
using System.Web.UI;

namespace Al.UI.Controls
{
    public class RepeaterHeaderItem: RepeaterItem
    {
        public RepeaterHeaderItem(int itemIndex):base(itemIndex)
        {
        }

        struct Constants
        {
            public const string Width = "100%";
            public const string ImageWidth = "10px";
            public const string ImageId = "{0}_Img";
            public const string CellPadding = "0";
            public const string CellSpacing = "0";
        }

        protected override void Render(HtmlTextWriter writer)
        {
            writer.AddAttribute(HtmlTextWriterAttribute.Id, this.ClientID);
            writer.RenderBeginTag(HtmlTextWriterTag.Div);

            writer.AddStyleAttribute(HtmlTextWriterStyle.Width, Constants.Width);
            writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, Constants.CellPadding);
            writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, Constants.CellSpacing);
            writer.RenderBeginTag(HtmlTextWriterTag.Table);
            writer.RenderBeginTag(HtmlTextWriterTag.Tr);

            writer.AddStyleAttribute(HtmlTextWriterStyle.Width, Constants.ImageWidth);
            writer.RenderBeginTag(HtmlTextWriterTag.Td);
            this.RenderExpandImage(writer);
            writer.RenderEndTag();

            writer.RenderBeginTag(HtmlTextWriterTag.Td);
            base.Render(writer);
            writer.RenderEndTag();

            //For Table
            writer.RenderEndTag();
            writer.RenderEndTag();
            
            //For Div
            writer.RenderEndTag();
        }

        private void RenderExpandImage(HtmlTextWriter writer)
        {
            writer.AddAttribute(HtmlTextWriterAttribute.Id, String.Format(Constants.ImageId, this.ClientID));
            writer.RenderBeginTag(HtmlTextWriterTag.Img);
            writer.RenderEndTag();
        }
    }
}
